//
//  MyAddTableViewCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/20.
//  Copyright © 2016年 game. All rights reserved.
//

#import "MyAddTableViewCell.h"
#import "TYAttributedLabel.h"

@interface MyAddTableViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *head;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headWidth;
@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *userName;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *time;
@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *action;

@property (weak, nonatomic) IBOutlet UILabel *footView;
@property (weak, nonatomic) IBOutlet TYAttributedLabel *content;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *footHeight;

@end

@implementation MyAddTableViewCell

- (void)awakeFromNib {

    self.selectionStyle = 0;
    self.footView.backgroundColor = tabPlainBackColor;
    self.footHeight.constant = SCREEN_HEIGHT*0.03;
    
    self.headHeight.constant = SCREEN_WIDTH*0.07;
    self.headWidth.constant = self.headHeight.constant;
    radius(self.head, self.headHeight.constant/2);
    
    self.action.layer.borderColor = mainColor.CGColor;
    self.action.layer.borderWidth = 0.5;
    
   
}

-(void)setModel:(MyAddListModel *)model{
    _model = model;
    [self.head sd_setImageWithURL:[NSURL URLWithString:_model.avatar] forState:UIControlStateNormal];
    [self.userName setTitle:_model.author forState:UIControlStateNormal];
    self.time.text = _model.dateline;
    
    self.content.backgroundColor = [UIColor clearColor];
    
    NSString *text = _model.note;
    
    NSArray *textArray = [text componentsSeparatedByString:@"\t"];
    
    NSArray *colorArray = @[[UIColor lightGrayColor],textcolor];
    
    NSInteger index = 0;
    
    for (NSString *text in textArray) {
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];
        
        // 设置当前文本颜色
        [attributedString addAttributeTextColor:colorArray[index%5]];
        
        // 设置当前文本字体
        [attributedString addAttributeFont:[UIFont systemFontOfSize:SCREEN_WIDTH*0.045]];
        //        self.content.characterSpacing = 2;
        // 追加(添加到最后)属性文本
        [self.content appendTextAttributedString:attributedString];
        [self.content appendText:@"\t"];
        index++;
    }
    
    [self.content sizeToFit];
    
    self.content.preferredMaxLayoutWidth = SCREEN_WIDTH-36;
    CGFloat Hhhh = [self.content getHeightWithWidth:SCREEN_WIDTH-36];
    
    self.contentHeight.constant = Hhhh;
    
    self.cellHight = Hhhh+SCREEN_HEIGHT*0.15;


}
- (IBAction)spaceAction:(UIButton *)sender {
    
    if ([self.deleget respondsToSelector:@selector(ToSpaceWhithUid:)]) {
        
        [self.deleget ToSpaceWhithUid:_model.from_id];
    }
}


- (IBAction)OkAction:(MBButtonWithFontAdapter *)sender {
    
    
     [[Manager sharedManager]RequestWhithURL:GetFormhash AndParameter:nil AndCompletionType:^(id responseObject, DIEError *error) {
        if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {

            [self AgreeWhithFormhash:responseObject[@"data"][@"formhash"]];
        }
    }];

    
}

-(void)AgreeWhithFormhash:(NSString *)formhash{

    NSDictionary *dic = @{@"formhash":formhash,@"uid":_model.from_id};
    [[Manager sharedManager]ResponseWhithURL:AgreeAdd AndParameter:dic AndCompletionType:^(id responseObject, DIEError *error) {
      
        
        if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {
            
            if ([self.deleget respondsToSelector:@selector(agreeWhithCell:AndMessage:AndIsSucces:)]) {
                
                [self.deleget agreeWhithCell:self AndMessage:responseObject[@"message"] AndIsSucces:YES];
            }
            
        }else{
        
            if ([self.deleget respondsToSelector:@selector(agreeWhithCell:AndMessage:AndIsSucces:)]) {
                
                [self.deleget agreeWhithCell:self AndMessage:responseObject[@"message"] AndIsSucces:YES];
            }

        
        }

    }];

}

@end
